Skip to content

Migrate from TensorAlgebra macro lazy types to LinearBroadcasted#139

Merged
mtfishman merged 7 commits intomainfrom
mf/linear-broadcasted
Mar 27, 2026
Merged

Migrate from TensorAlgebra macro lazy types to LinearBroadcasted#139
mtfishman merged 7 commits intomainfrom
mf/linear-broadcasted

Conversation

@mtfishman
Copy link
Copy Markdown
Member

@mtfishman mtfishman commented Mar 25, 2026

Summary

Companion PR to ITensor/TensorAlgebra.jl#156 — migrates GradedArrays from the old macro-generated lazy types to the new LinearBroadcasted design.

What changed

  • Delete ScaledGradedArray, ConjGradedArray, AddGradedArray and all macro-generated lazy types
  • Delete lazyblock, graded_eachblockstoredindex, copy_lazygraded, check_graded_broadcast_axes, check_sector_broadcast_axes
  • Replace BC.broadcasted(::GradedStyle/SectorStyle, ...) eager interception with copyto! instantiation-time conversion via tryflattenlinear
  • Add permutedimsopadd! overloads for GradedArray and SectorArray as the single materialization primitives
  • Update permutedimsadd!permutedimsopadd! with op parameter in tensoralgebra.jl
  • Replace y .*= β with blockwise scaling to avoid broadcasting cycle (instantiation-time copyto! intercepts all broadcasting on these types)
  • Add similar(::Broadcasted{SectorStyle}) (previously not needed since broadcasting was eager)
  • Net -147 lines in broadcast.jl (230 → 83)

Known issues

  • matricize/contract tests fail — these go through permutedimsopadd! on BlockSparseArray blocks (not GradedArray), where the default implementation wraps in PermutedDimsArray and broadcasts. Needs investigation — may require a BlockSparseArray permutedimsopadd! overload or fixing the PermutedDimsArray + BlockSparseArray broadcast interaction.
  • similar(::Broadcasted{SectorStyle}) is a temporary implementation — should be reworked to strip sectors, delegate similar, and re-wrap.
  • Broadcasting tests all pass.

Dependencies

Test plan

  • SectorArray broadcasting tests pass
  • GradedArray broadcasting tests pass
  • matricize/contract tests (known failures, needs investigation)
  • Full Pkg.test() pass

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

Your PR no longer requires formatting changes. Thank you for your contribution!

mtfishman and others added 2 commits March 25, 2026 20:03
- Delete ScaledGradedArray, ConjGradedArray, AddGradedArray and all
  macro-generated lazy types
- Delete lazyblock, graded_eachblockstoredindex, copy_lazygraded
- Replace BC.broadcasted(::GradedStyle/SectorStyle, ...) eager
  interception with copyto! instantiation-time conversion via
  tryflattenlinear
- Add permutedimsopadd! overloads for GradedArray and SectorArray
- Update permutedimsadd! → permutedimsopadd! with op parameter in
  tensoralgebra.jl
- Replace y .*= β with blockwise scaling to avoid broadcasting cycle
- Bump TensorAlgebra compat to 0.7.21, 0.8
- Bump version to 0.6.24

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mtfishman mtfishman force-pushed the mf/linear-broadcasted branch from c5e8df5 to 956eb08 Compare March 26, 2026 00:04
mtfishman and others added 5 commits March 25, 2026 20:08
Block indexing on GradedArray (y[Block(...)]) returns a copy, not a
view. Use @view! to get a mutable view into the block, so that
permutedimsopadd! writes actually persist in the destination array.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
With instantiation-time broadcast conversion, axis checking happens in
Base.Broadcast.combine_axes which throws DimensionMismatch instead of
the old ArgumentError from check_graded_broadcast_axes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mtfishman mtfishman marked this pull request as ready for review March 27, 2026 01:39
@mtfishman mtfishman changed the title [WIP] Migrate from TensorAlgebra macro lazy types to LinearBroadcasted Migrate from TensorAlgebra macro lazy types to LinearBroadcasted Mar 27, 2026
@mtfishman mtfishman closed this Mar 27, 2026
@mtfishman mtfishman reopened this Mar 27, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.03%. Comparing base (76cc220) to head (84c98e1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #139      +/-   ##
==========================================
- Coverage   71.90%   70.03%   -1.88%     
==========================================
  Files          11       11              
  Lines        1164     1118      -46     
==========================================
- Hits          837      783      -54     
- Misses        327      335       +8     
Flag Coverage Δ
docs 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant